diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index 2f6f8f14..eb332288 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -22,16 +22,17 @@ ENDIF(INSTALL_HELPER_SCRIPTS)
 # Inspired by http://bloerg.net/2012/11/10/cmake-and-distutils.html
 
 FIND_PROGRAM(PYTHON "python3")
-IF(PYTHON)
-    SET(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
-    SET(SETUP_PY    "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
-    SET(DEPS_IN     "${CMAKE_CURRENT_SOURCE_DIR}/lensfun/__init__.py.in")
-    SET(DEPS        "${CMAKE_CURRENT_BINARY_DIR}/lensfun/__init__.py")
-    SET(OUTPUT      "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
 
-    CONFIGURE_FILE(${SETUP_PY_IN} ${SETUP_PY})
-    CONFIGURE_FILE(${DEPS_IN} ${DEPS})
+SET(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
+SET(SETUP_PY    "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
+SET(DEPS_IN     "${CMAKE_CURRENT_SOURCE_DIR}/lensfun/__init__.py.in")
+SET(DEPS        "${CMAKE_CURRENT_BINARY_DIR}/lensfun/__init__.py")
+SET(OUTPUT      "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
 
+CONFIGURE_FILE(${SETUP_PY_IN} ${SETUP_PY})
+CONFIGURE_FILE(${DEPS_IN} ${DEPS})
+
+IF(INSTALL_PYTHON_MODULE)
     ADD_CUSTOM_COMMAND(OUTPUT ${OUTPUT}
                        COMMAND ${PYTHON} ${SETUP_PY} build
                        COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
@@ -43,4 +44,4 @@ IF(PYTHON)
       SET(SETUP_PY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
     ENDIF()
     INSTALL(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install --prefix=\$ENV{DESTDIR}${SETUP_PY_INSTALL_PREFIX})")
-ENDIF(PYTHON)
+ENDIF(INSTALL_PYTHON_MODULE)
